package com.wuzuqing.android.eightdiagrams.task;

import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaItem;
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaModel;
import com.wuzuqing.android.eightdiagrams.utils.DataUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @CopyRight: 广州仰望星空云科技有限公司
 * @Author : wuzuqing
 * @Email:wuzuqing@xinyu668.com
 * @CreateTime: 26.7.24 3:30 PM
 * @Description: 请写描述
 */
public class QiMenDunJiaStep3Task extends IQiMenDunJiaTask {
    QiMenDunJiaModel model;

    public QiMenDunJiaStep3Task(QiMenDunJiaModel model) {
        this.model = model;
    }

    @Override
    public void handleTask() {
        String[] sanQiLiuYi = new String[]{"戊", "己", "庚", "辛", "壬", "癸", "丁", "丙", "乙"};
        int[] gongArr = new int[9];
        List<QiMenDunJiaItem> list = model.getList();
        int juShu = model.getJuShu();
        boolean isYangDun = model.isYangDun();
        if (isYangDun) {
            for (int i = 0; i < gongArr.length; i++) {
                gongArr[i] = (juShu + i);
                if (gongArr[i] > 9) {
                    gongArr[i] -= 9;
                }
            }
        } else {
            for (int i = 0; i < gongArr.length; i++) {
                gongArr[i] = (juShu - i);
                if (gongArr[i] <= 0) {
                    gongArr[i] += 9;
                }
            }
        }
        List<String> baZi = model.getLunar().getBaZi();
        String shiGan = baZi.get(3).charAt(0) + "";
        boolean isShiGanJia = "甲".equals(shiGan);
        for (int i = 0; i < gongArr.length; i++) {
            QiMenDunJiaItem dunJia = getDunJia(list, gongArr[i]);
            if (dunJia != null) {
                dunJia.setDiPanGan(sanQiLiuYi[i]);
                if (dunJia.getGongNum() == 5) {
                    QiMenDunJiaItem temp = getDunJia(list, 2);
                    if (temp != null) {
                        temp.setAppendDiPanGan(sanQiLiuYi[i]);
                    }
                }
                if (isShiGanJia) {
                    dunJia.setTianPanGan(dunJia.getDiPanGan());
                }
            }
        }
        model.setShiGanJia(isShiGanJia);
//        System.out.println("第三步:布地盘三奇六仪");
    }
}
